﻿namespace YAPACS.RisServer.Services.ECharts;

/// <summary>
/// 数据源
/// </summary>
public class DataSource
{
    /// <summary>
    /// 源
    /// </summary>
    public List<object> Source { get; set; } = [];


    /// <summary>
    /// 维度名称定义
    /// </summary>
    public List<object> Dimensions { get; set; }


    /// <summary>
    /// 数据转换
    /// （本属性有值的状态下获取数据源schema的时候是不把 Source和Dimension 添加到schema的）
    /// </summary>
    public object Transform { get; set; }


    /// <summary>
    /// 获取数据源Schema
    /// </summary>
    /// <returns></returns>
    public Dictionary<string, object> GetSchema()
    {
        Dictionary<string, object> schema = [];
        if (Transform != null)
        {
            schema.Add("transform", Transform);
        }
        else
        {
            if (Dimensions != null)
            {
                schema.Add("dimensions", Dimensions);
            }
            if (Source != null)
            {
                schema.Add("source", Source);
            }
        }
        return schema;
    }
}
